home *** CD-ROM | disk | FTP | other *** search
- Unit SSaveWin;
-
- {****************************************************************************
- *****************************************************************************
- * *
- * SsaveWin.pas: *
- * Unit for Windows 3.1 Screen Savers. Exports the object type for the *
- * screen saver main window, TScSaverWin. *
- * *
- * Compiler: BP 7.0 *
- * *
- * See SSaveDem.pas. *
- * *
- *****************************************************************************
- * *
- * Copyright ⌐ 1993 Manfred Keul [100031,12]. *
- * *
- * Rev. 0.1 28.3.93 MK IR *
- * *
- *****************************************************************************
- ****************************************************************************}
-
- interface
-
- uses Objects, OWindows, Wintypes, Winprocs, SsavePwd;
-
- {****************************************************************************
- * *
- * T S c S a v e r W i n *
- * *
- * Main window of a screen saver. *
- * *
- * When the screen saver "strikes", an instance of this window type will *
- * cover the whole screen. When the next mouse or keyboard event occurs, *
- * the method Stop asks for the password (if one is enabled). If the user *
- * enters the correct password, a WM_CLOSE message is posted - which *
- * should end the life cycle of this window. *
- * *
- * Default attributes of this window class: No cursor, "Black_Brush" as *
- * background, (WS_POPUP or WS_VISIBLE) *
- * *
- * The Application is expected to call DoTheShow within its IdleAction *
- * method. So, DoTheShow is the method to put any animation into. *
- * *
- ****************************************************************************}
-
- type
- PScSaverWin = ^TScSaverWin;
- TScSaverWin = Object(TWindow)
- constructor Init(aParent:PWindowsObject; aTitle:PChar);
- function GetClassName: PChar; virtual;
- procedure GetWindowClass (var aWndClass: TWndClass); virtual;
- procedure WMActivate (var Msg: TMessage);virtual wm_first+WM_ACTIVATE;
- procedure WMMousemove (var Msg: TMessage);virtual wm_first+WM_MOUSEMOVE;
- procedure WMLbuttondown (var Msg: TMessage);virtual wm_first+WM_LBUTTONDOWN;
- procedure WMRbuttondown (var Msg: TMessage);virtual wm_first+WM_RBUTTONDOWN;
- procedure WMMbuttondown (var Msg: TMessage);virtual wm_first+WM_MBUTTONDOWN;
- procedure WMSyskeydown (var Msg: TMessage);virtual wm_first+WM_SYSKEYDOWN;
- procedure WMKeydown (var Msg: TMessage);virtual wm_first+WM_KEYDOWN;
- procedure Stop (var Msg: TMessage); virtual;
- procedure DoTheShow; virtual;
- end;
-
-
- {****************************************************************************
- * *
- * I m p l e m e n t a t i o n *
- * *
- ****************************************************************************}
-
- implementation
-
- var LastMouse: Tpoint;
-
- {****************************************************************************
- * *
- * T S c S a v e r W i n . G e t C l a s s N a m e, *
- * - . G e t W i n d o w C l a s s, *
- * - . I n i t *
- * *
- * Register the window class and set the default attributes. *
- * *
- ****************************************************************************}
-
- function TScSaverWin.GetClassName: PChar;
- begin
- GetClassName := 'BPScreenSaver';
- end;
-
- procedure TScSaverWin.GetWindowClass (var aWndClass:TWndClass);
- begin
- inherited GetWindowClass (aWndClass);
- aWndClass.hCursor := 0 ;
- aWndClass.hbrBackground := GetStockObject (Black_Brush);
- end;
-
- constructor TScSaverWin.Init (aParent: PWindowsObject; aTitle: PChar);
- begin
- inherited Init (aParent, aTitle);
- with Attr do
- begin
- Style := WS_POPUP or WS_VISIBLE;
- X := 0; { let window....}
- Y := 0;
- W := GetSystemMetrics (SM_CXSCREEN);
- H := GetSystemMetrics (SM_CYSCREEN); {...cover the whole screen }
- end;
- end;
-
- {****************************************************************************
- * *
- * T S c S a v e r W i n . W M A c t i v a t e *
- * *
- * Stores mouse position when screen saver starts. *
- * *
- * OUTPUT: LastMouse = mouse position *
- * *
- ****************************************************************************}
-
- procedure TScSaverWin.WMActivate (var Msg: TMessage);
- begin
- if (Msg.wParam <> 0) then { are we going to be activated? }
- GetCursorPos (LastMouse); { then get mouse position }
- DefWndProc (Msg);
- end;
-
- {****************************************************************************
- * *
- * T S c S a v e r W i n . W M M o u s e M o v e *
- * *
- * Checks if mouse has been moved to a new position. If so, calls STOP. *
- * *
- * INPUT: LastMouse = mouse position on last saver activation *
- * *
- ****************************************************************************}
-
- procedure TScSaverWin.WMMouseMove (var Msg: TMessage);
-
- var CurrMouse: Tpoint;
-
- begin
- SetCursor (0); { Hide cursor again }
- GetCursorPos (CurrMouse); { Where's the mouse? }
-
- { Most screen savers I examined used a to -1 initialized variable for LastMouse
- and contained the following test on -1. I don't see the reason why. If some-
- body does, he or she should a) remove the braces around the test and b) ex-
- plain this to me so that I don't have to die stupid. }
- { if (LastMouse.x = -1) then
- GetCursorPos (LastMouse)
- else }
-
- if (LastMouse.x <> CurrMouse.x) or (LastMouse.y <> CurrMouse.y) then
- Stop (Msg); { call Stop in case of new mouse position }
-
- DefWndProc (Msg);
- end;
-
- {****************************************************************************
- * *
- * T S c S a v e r W i n . W M x b u t t o n d o w n, *
- * - . W M x K e y d o w n *
- * *
- * Frontends that just call Stop on any key event. *
- * *
- * NOTE: How about Borland to add dynamic methods with multiple indices? *
- * *
- ****************************************************************************}
-
- procedure TScSaverWin.WMLbuttondown (var Msg: TMessage);
- begin Stop (Msg); end;
-
- procedure TScSaverWin.WMRbuttondown (var Msg: TMessage);
- begin Stop (Msg); end;
-
- procedure TScSaverWin.WMMbuttondown (var Msg: TMessage);
- begin Stop (Msg); end;
-
- procedure TScSaverWin.WMSyskeydown (var Msg: TMessage);
- begin Stop (Msg); end;
-
- procedure TScSaverWin.WMKeydown (var Msg: TMessage);
- begin Stop (Msg); end;
-
- {****************************************************************************
- * *
- * T S c S a v e r W i n . S t o p *
- * *
- * Closes the screen saver window if the PasswordOK function from unit *
- * SsavePwd says that it's ok to do do. *
- * *
- ****************************************************************************}
-
- procedure TScSaverWin.Stop (var Msg: TMessage);
- begin
- if PasswordOK (@Self) then
- PostMessage (HWindow, WM_CLOSE, 0, 0);
- DefWndProc (Msg);
- end;
-
- {****************************************************************************
- * *
- * T S c S a v e r W i n . D o T h e S h o w *
- * *
- * Animates the screen - well, at least its descendants should... *
- * *
- ****************************************************************************}
-
- procedure TScSaverWin.DoTheShow;
- begin
- end;
-
-
- begin
- end.
-
-